<template>
    <div class="fullScreen bg-c-wh tx-c-666">
        <m-header :msg="'修改赔率'"></m-header>
        <div class="tx-s-14 tx-c-666 pad-lr">
            <div class="flex-box flex-ac flex-pj bor-b-g mar-t-5"> 
                <div class="flex-box wd-50">
                    <input class="tx-c-222 input-ol-n wid-9" v-model="pl" type="number" @input="oninput" placeholder="请输入赔率百分比"/>
                    <div>%</div>
                </div>
                <div class="pad-btn" @click="resetIpt('')">
                    <div class="iconSize-1 icon_delet"></div>
                </div>
            </div>
            <div class="mar-t-5">· 请输入此用户的赔率百分比</div>
            <div class="flex-box flex-pa mar-t-3">
                <div class="cancel-btn-s" @click="resetIpt($route.query.pl)">重置</div>
                <div class="submit-btn-s" @click="modify()">修改</div>
            </div> 
        </div>
    </div>
</template>
<script type="text/ecmascript-6">
import 'common/css/user.css'
import MHeader from '../../components/m-header'
import { isEmptyObject } from '../../common/js/common'
import { oddsModify } from '../../common/js/axiosUtil' 
export default { 
    data() {
        return { 
            pl : this.$route.query.pl
        }
    },
    methods: {
        // 通过正则过滤小数点后两位
        oninput(e) {
            this.pl = (e.target.value.match(/^\d*(\.?\d{0,1})/g)[0]) || null
        },
        // 清除/重置赔率
        resetIpt (index) {
            this.pl = index
        },
        // 修改赔率
        modify () {
            let params = this.$params(1)
            params.append('oid', this.$route.query.id)
            params.append('pl', this.pl)
            oddsModify(params)
            .then((response)=> {
                // 修改成功
                if(response.data.code == "200"){
                    this.$toast('修改成功', 2000)
                    // 返回上一页
                    let _this = this
                    setTimeout(function(){
                        _this.$toastClose()
                        _this.$router.go(-1) 
                    }, 1000)
                } else {
                    this.$logAgain(response.data.msg)
                }
            })
            .catch((error)=> {
                this.$toast('请求服务失败', 2000)
            })
        }
    },
    components: {
        MHeader
    }
}
</script>
<style scoped lang="stylus" rel="stylesheet/stylus">
    .pad-lr
        padding: 0 1rem
    .pad-btn
        padding : 1rem .25rem 1rem 1rem
    .wid-9
        width: 90%
</style>

